From: Ewan Mellor Date: Fri, 5 Jan 2007 12:30:32 +0000 (+0000) Subject: Treat tags with no type tag inside as if they were strings (as required X-Git-Tag: archive/raspbian/4.8.0-1+rpi1~1^2~15422^2~76 X-Git-Url: https://dgit.raspbian.org/%22http:/www.example.com/cgi/%22https://%22%22/%22http:/www.example.com/cgi/%22https:/%22%22?a=commitdiff_plain;h=800c66b2642c9101ace90f48cb643f4636d1d545;p=xen.git Treat tags with no type tag inside as if they were strings (as required by the XML-RPC spec). Signed-off-by: Ewan Mellor --- diff --git a/tools/libxen/src/xen_common.c b/tools/libxen/src/xen_common.c index c380b85190..9834565ff0 100644 --- a/tools/libxen/src/xen_common.c +++ b/tools/libxen/src/xen_common.c @@ -373,11 +373,18 @@ static void server_error_2(xen_session *session, const char *error_string, } -static bool is_container_node(xmlNode *n, char *type) +static bool is_node(xmlNode *n, char *type) { return n->type == XML_ELEMENT_NODE && - 0 == strcmp((char *)n->name, type) && + 0 == strcmp((char *)n->name, type); +} + + +static bool is_container_node(xmlNode *n, char *type) +{ + return + is_node(n, type) && n->children != NULL && n->children == n->last && n->children->type == XML_ELEMENT_NODE; @@ -390,13 +397,30 @@ static bool is_container_node(xmlNode *n, char *type) */ static xmlChar *string_from_value(xmlNode *n, char *type) { - return - is_container_node(n, "value") && - 0 == strcmp((char *)n->children->name, type) ? - (n->children->children == NULL ? - xmlStrdup(BAD_CAST("")) : - xmlNodeGetContent(n->children->children)) : - NULL; + /* + XYZ is normal, but the XML-RPC spec also + allows XYZ where XYZ is to be interpreted as a string. + */ + + if (is_container_node(n, "value") && + 0 == strcmp((char *)n->children->name, type)) + { + return + n->children->children == NULL ? + xmlStrdup(BAD_CAST("")) : + xmlNodeGetContent(n->children->children); + } + else if (0 == strcmp(type, "string") && is_node(n, "value")) + { + return + n->children == NULL ? + xmlStrdup(BAD_CAST("")) : + xmlNodeGetContent(n->children); + } + else + { + return NULL; + } }